<?php
namespace Admin\Controller;
use Think\Controller;
class WechatController extends CommonController {
    public function index(){
    	if(IS_AJAX){
            $model = M("Wechat");
            $map = array();
            $res['count'] = $model->where($map)->count();
            $page = $_GET['page']?$_GET['page']:1;
            $limit = $_GET['limit']?$_GET['limit']:10;
            $res['list'] = $model->where($map)->page("{$page},{$limit}")->select();

            $this->ajaxReturn($res);
        }else{
            $this->display();
        }
    }
    //审核生成小程序请求页面
    public function audit()
    {
        if(IS_AJAX){
            $model = M("shop");
            $map = array(
                "has_mini"=>['egt',1],
                "status"=>1,
                "is_pay"=>1
            );
            $res['count'] = $model->where($map)->count();
            $page = $_GET['page']?$_GET['page']:1;
            $limit = $_GET['limit']?$_GET['limit']:10;
            $res['list'] = $model->where($map)->page("{$page},{$limit}")->order("has_mini asc")->select();
            $this->ajaxReturn($res);
        }else{
            $this->display();
        }
    }
    //审核生成小程序请求
    public function auditc()
    {
        if(IS_AJAX){
            $model = M("shop");
            $map = array(
                "shop_id"=>I("id")
            );
            $new['has_mini'] =2;
            $r = $model->where($map)->save($new);
            if($r){
                sendAuditMessage(I("id"),'mini');
                $this->success('审核成功！');
            } else {
                $this->success('审核失败~');
            }

        }
    }

    public function edit(){
        $model = M("Wechat");
        $map['wid'] = $_GET['id'];

        if(IS_AJAX){
            $new['end_time'] = I('post.end_time');
            $model->where($map)->save($new);
            $this->success('修改成功！');
        }else{
            $vo = $model->where($map)->find();
            $this->assign('vo',$vo);
            $this->display();
        }
    }

    public function xian(){
        $model = M("Wechat");
        $map['wid'] = $_POST['id'];

        $new['status'] = $_POST['status'];
        if($model->where($map)->save($new)){
            $this->success("设置成功！");
        }else{
            $this->error("网络忙，请稍后再试！".$model->getLastSql());
        }
    }
}